package com.cskaoyan.util;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.exception.ValidationException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * 
 * 创建日期: 2022/05/07 19:18
 * @author wangyonghong
 */
 
public class InvalidUtils {

    static public void invalid( BindingResult bindingResult) throws ValidationException {
        if (bindingResult.hasFieldErrors()){
            FieldError fieldError = bindingResult.getFieldError();
            Object rejectedValue = fieldError.getRejectedValue();
            String field = fieldError.getField();
            String defaultMessage = fieldError.getDefaultMessage();
            String msg="请求参数"+field+"因为传入了值"+rejectedValue+"无法通过校验"+defaultMessage;
           throw new ValidationException(msg);
        }

    }
}
